package com.atguigu.service;

import com.atguigu.exception.CustomException;
import com.atguigu.mapper.DepartmentMapper;
import com.atguigu.pojo.Account;
import com.atguigu.pojo.Department;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {

    @Resource
    private DepartmentMapper departmentMapper;


    public void add(Department department) {

        departmentMapper.add(department);
    }

    public void deleteById(Integer id) {
        departmentMapper.deleteById(id);
    }

    public void update(Department department) {
        departmentMapper.update(department);
    }

    public List<Department> selectAll(Department department) {
        return departmentMapper.selectAll(department);
    }

    public Department selectById(Integer id) {
        return departmentMapper.selectById(id);
    }

    public PageInfo<Department> selectPage(Department department, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Department> list = departmentMapper.selectAll(department);
        return PageInfo.of(list);
    }


    public void deleteBatch(List<Integer> ids) {
        for(Integer id : ids) {
            departmentMapper.deleteById(id);
        }
    }

}
